package com.yyk.yiliao.ui.login.activity;

import android.content.Intent;
import android.os.Handler;

import com.hyphenate.chat.EMClient;
import com.orhanobut.hawk.Hawk;
import com.yyk.yiliao.R;
import com.yyk.yiliao.base.BaseActivity;
import com.yyk.yiliao.ui.Main_Activity;

public class Welcome_Activity extends BaseActivity {
    private Handler handler = new Handler();


    @Override
    protected void onStart() {
        super.onStart();
        //登录成功后需要调用EMClient.getInstance().chatManager().loadAllConversations(); 和EMClient.getInstance().groupManager().loadAllGroups();
        EMClient.getInstance().chatManager().loadAllConversations();
        EMClient.getInstance().groupManager().loadAllGroups();
        //以上两个方法是为了保证进入主页面后本地会话和群组都 load 完毕。
    }

    private void initWelcome() {
        String MAIN_ACTIVITY = Hawk.get("MAIN_ACTIVITY", "0");
        //true 跳转到 主页面   false跳转到 首次安装界面
        if (MAIN_ACTIVITY.equals("0")) {

            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    Intent intent = new Intent(Welcome_Activity.this, First_Activity.class);
                    startActivity(intent);
                    finish();
                }
            }, 2000);

        } else if (MAIN_ACTIVITY.equals("2")) {

            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    Intent intent = new Intent(Welcome_Activity.this, Main_Activity.class);
                    startActivity(intent);
                    finish();
                }
            }, 2000);

        }
// else {  //2
//
//            handler.postDelayed(new Runnable() {
//                @Override
//                public void run() {
//                    Intent intent = new Intent(Welcome_Activity.this, Main_Activity.class);
//                    startActivity(intent);
//                    finish();
//                }
//            }, 1000);
//        }

    }


    @Override
    public int getLayoutId() {
        return R.layout.activity_welcome;
    }

    @Override
    public void initView() {
        initToolbar();
        initWelcome();

    }

    private void initToolbar() {
        hidetoolBar();
    }

    @Override
    public void initData() {

    }

}
